This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.

MIND

Web Q&A
Web Q&A:Windows Script Host, Dropdown Menus, ASP-to-HTML, and More
Robert Hess

Q I recently read an article about Windows Script Host (WSH) 2.0. Before I become really interested, I have one question: can I use WSH to rename existing files? I downloaded the latest documentation from Microsoft, but I found no mention of this.

A Yes, you can. Through the use of the FileSystem object (as well as the File object) you can effectively rename files. The problem is you would expect to find it in the documentation under a name like Rename. Actually, the functionality is supplied via the MoveFile method. The only technical difference between a file move and a rename is that move usually indicates the ability to change the location of the file in addition to the name.
      This code will effectively rename the file test.txt to temp.txt:

  
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile "test.txt, "temp.txt"

Of course, a well-crafted solution would also incorporate appropriate error handling to deal with the case in which the source file doesn't exist, or the destination file already exists.

Q I have noticed the neat toolbar on the microsoft.com Web sites. I was wondering how those dropdown menus were designed. I've looked through the Backstage site (https://www.microsoft.com/backstage), to no avail.

A One of the beauties of the Web is that many of the interesting features people add to their Web sites are easily examined by simply looking at the source code for the pages, which (for the time being anyway) is still being sent to the browser as plain text.
      While it might be a little confusing and take a while to decipher, I heartily recommend that budding Web designers and programmers regularly take a look at the code at the sites they visit to see how they are accomplishing various effects. It is amazing what you can learn just by tracing someone's steps.
      By going to the Microsoft home page (https://www.microsoft.com) and doing a View | Source, you can trace the steps necessary to duplicate the toolbar. It would be a tad misleading to say this is easy to reproduce. You will need to have a good understanding of JavaScript, Dynamic HTML, and Cascading Style Sheets in order to decipher precisely what is going on, since these languages are used to generate the dropdown menus.
      First, go to the Microsoft home page, select View | Source, and save the file to your hard drive from Notepad. Next, look through this source code. Several lines down you will see the following:

  
<script language="JavaScript"
src='/library/toolbar/toolbar.js'></script>
<script language="JavaScript"
src='/library/toolbar/en-us/global.js'></script>
<script language="JavaScript"
src='/library/toolbar/en-us/local.js'></script>

These lines indicate where you can find some additional JavaScript code that's being used on this page. To view it, simply type in the URL (https://www.microsoft.com/library/toolbar/toolbar.js) in your browser.
      This will allow you to save the file to your local hard drive. Do this for all three files and save them to the same location you used in the first step.
      Open up the source HTML file that you saved earlier on your hard drive, and edit the three lines that I pointed out. Remove the path information for the src attribute so that all you have left is the file name itself (toolbar.js, global.js, and local.js), and then save this file back to your drive.
      Now, open the HTML file you just saved in your browser. Aside from the fact that the images will not be found and most of the links will be broken, the toolbar should work. You now have all of the code necessary for the toolbar on your local machine.
      By playing around with the code that you have downloaded, you should be able to see how this all comes together. No, the code presented is not quite as simple as inserting some canned functionality into your page that will magically work. You'll need to sweat a little in order to customize the code to meet your needs.

Q How can I launch an instance of Microsoft Internet Explorer 4.0 or later that does not have a toolbar or navigation bars? I sometimes want to call the browser from within my application, but I don't want to permit navigation.

A I expect that there are perhaps some command-line options that might be able to do this, but I wasn't able to find any specific information. I do know that the -k switch will bring Internet Explorer up in kiosk mode, and that -channelband will bring up the channel band.
      However, I don't think a command-line method would really be the best way to do this. My preference would be to take a more active role in controlling what Internet Explorer is doing, and the best way to do this is via scripting.
      WSH is automatically installed with Windows 98 and Windows 2000, and can be downloaded for Windows 95 and Windows NT 4.0 from https://msdn.microsoft.com/scripting. If a system has WSH installed, then you can create a script file that will open up Internet Explorer and control whether the toolbar is visible (as well as perform other tasks). For example, this code will open a session of the browser and send it to the Microsoft Web site.

  
    Dim objIE
    Set objIE = WScript.CreateObject __
    ("InternetExplorer.Application")
    objIE.Toolbar = false
    objIE.Navigate "https://www.microsoft.com"
    objIE.Visible = true

      If you save this file as msft.vbs and execute it, it will open up a view to the Microsoft Web site without displaying a toolbar. From this script code, you have full access to Internet Explorer as a programmable object, and can control other features and capabilities of the browser.

Q We have been using ASP to create every type of page imaginable. The convenience of pointing a user to a Web-based data entry page for everything is great, but there is no reason for us to create a dynamic Web page for every user's input because some of these pages only change once a month. Is there some sort of ASP-to-HTML component that I can use to generate unchanging HTML code along the lines of "this is how your content will appear on the published page" without making it data-driven every time it's requested?

A The book Microsoft Internet Information Server Resource Kit (Microsoft Press, 1998) includes a companion CD that provides several different installable ASP components. One of them is "ASP to HTML," and sounds like it would do pretty much what you want. You could always be a fellow geek and feel obligated to write one yourself!

Q I have an ASP page that calls an ActiveX DLL from an intranet site. The DLL performs a lengthy database task. Unfortunately, while the task is in progress, Internet Explorer 5.0 decides that it has waited long enough and sends an error page back to the client. I have tried Response.Expires = 0 and setting the script timeout as high as possible. It appears that Internet Explorer will wait about three to five minutes for the DLL to finish its work before sending the error page. Is there a setting to force the browser to wait until the DLL in the ASP page is finished, either within the ASP code or for users within their browsers?

A First, I question the appropriateness of having such a long database task without providing feedback about the status of the process or allowing users to cancel. Instead, perform the operation asynchronously from the Web page, and report on the progress.
      As for the time out problem, the Response.Expires property is designed for managing the caching of the Web page on the client, not for controlling the connection to the client. What you should do is set up a persistent HTTP connection by sending a Keep-Alive header to the client. This keeps the TCP/IP connection open between the client and server.
      In ASP, use the statement:

  
<% response.buffer = true %>

This automatically sets the Keep-Alive header. You should set this before any content is sent back from the server. I do it as the first line of my ASP file.
      In addition to setting Keep-Alive, this allows you to use the Response.Flush and Response.Clear methods in ASP. Flush will send all currently buffered content to the client, and Clear will remove any currently buffered content from the response buffer. This is handy if, during the page's script processing, you determine that the information you've already queued up to be sent is inappropriate. This can be easier than trying to maintain a string array with the entire outgoing HTML that you want to send.

Robert Hess is an engineer in the Microsoft Developer Relations group. He provides ISVs with information to help them develop apps for Microsoft systems software. Send e-mail to webqa@microsoft.com.

From the April 2000 issue of MSDN Magazine.